<?php
/*
 * @Author: your name
 * @Date: 2020-10-14 10:08:28
 * @LastEditTime: 2020-12-30 09:55:08
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙设置
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/FirewallSetController.php
 */
namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\service\module_manage\netfilter\FirewallSetService;
use think\facade\Request;

class FirewallSetController extends NetfilterBaseController
{
    /**
     * @name: linux防火墙配置修改
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 14:51:03
     */
    public function linuxFirewallConfigModify (\think\Request $request)
    {
        $input = $request->only(['main_switch', 'input', 'forward', 'output', 'host_id'],'post');
        $this->validate($input, 'FirewallSet.linuxSet');
        

        $FirewallSetService= new FirewallSetService();
        $FirewallSetService->linuxFirewallConfigModify($input);

        //下发命令
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut([],true);
    }

    /**
     * @name: windows防火墙配置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-12-15 14:44:58
     */
    public function windowsFirewallConfigModify (\think\Request $request)
    {
        $input = $request->only(['private_main_switch','public_main_switch','domain_main_switch','private_input','public_input','domain_input','private_output','public_output','domain_output','host_id'],'post');
        $this->validate($input, 'FirewallSet.windowsSet');

        $FirewallSetService= new FirewallSetService();
        $FirewallSetService->windowsFirewallConfigModify($input);

        //下发命令
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut([],true);
    }

    /**
     * @name: 接管控制防火墙
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-10-29 15:04:18
     */
    public function controlledFirewall ()
    {

        $input = Request::only(['host_id'], 'post');

        $this->validate($input, 'FirewallSet.controlFirewall');

        $FirewallSetService = new FirewallSetService();
        $FirewallSetService->controlFirewall();

        $this->sendCommandToClient('netfilter', 'controlledFirewall');
        return $this->jsonOutPut([], true);
    }

    /**
     * @name: 放弃接管防火墙
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-10-29 15:04:18
     */
    public function uncontrolledFirewall ()
    {
        $input = Request::only(['host_id', 'uncontrol_firewall_etime'], 'post');

        $this->validate($input, 'FirewallSet.controlFirewall');

        $FirewallSetService = new FirewallSetService();
        $FirewallSetService->uncontrolFirewall($input['uncontrol_firewall_etime']);

        $this->sendCommandToClient('netfilter', 'controlledFirewall');
        return $this->jsonOutPut([], true);
    }
}